<template>
  <div class="app-container">
    <div class="custom_card_0" v-show="showSearch">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="订单编号" prop="orderNo" label-width="80px">
          <el-input
            v-model="queryParams.orderNo"
            placeholder="请输入订单编号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item
          label="购买人姓名"
          prop="purchaserName"
          label-width="100px"
        >
          <el-input
            v-model="queryParams.purchaserName"
            placeholder="请输入购买人姓名"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item
          label="购买人手机号"
          prop="purchaserPhone"
          label-width="100px"
        >
          <el-input
            v-model="queryParams.purchaserPhone"
            placeholder="请输入购买人手机号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="成交时间" prop="tradingHours" label-width="100px">
          <el-date-picker
            clearable
            size="small"
            v-model="queryParams.tradingHours"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择成交时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['order:mkOrder:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['order:mkOrder:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['order:mkOrder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['order:mkOrder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->
    <div class="custom_card">
      <el-row  class="mb8">
        <el-tag style="margin-left: 10px">订单总金额:{{ orderTotal }}元</el-tag>
        <el-tag style="margin-left: 10px">佣金总金额:{{ totalCommission }}元</el-tag>
        <el-tag style="margin-left: 10px">一级佣金:{{ fristCommission }}元</el-tag>
        <el-tag style="margin-left: 10px">二级佣金:{{ secCommission }}元</el-tag>
      </el-row>
      <el-table v-loading="loading" :data="mkOrderList">
        <el-table-column label="订单编号" min-width="120" align="center" prop="orderNo" show-overflow-tooltip>
          <template slot-scope="{row}">
            <span style="font-size: 14px; color: #1890ff;cursor:pointer;" @click="handDetail(row)">{{ row.orderNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="成交时间" align="center" prop="tradingHours" min-width="120"></el-table-column>

<!--        <el-table-column label="平台服务费" align="center" prop="platformServiceFee"></el-table-column>-->

        <el-table-column label="购买人" align="center">
          <el-table-column label="客户名称" align="center" prop="purchaserName"/>
          <el-table-column label="手机号" align="center" prop="purchaserPhone"/>
          <el-table-column label="购买金额/元" align="center" prop="businessPrice"/>
        </el-table-column>

        <el-table-column label="一级分销" align="center">
          <el-table-column label="伙伴名称" align="center" prop="distributorsLevelOneName"/>
          <el-table-column label="手机号" align="center" prop="distributorsLevelOnePhone"/>
          <el-table-column label="分销金额/元" align="center" prop="primaryDistributionAmount"/>
        </el-table-column>


        <el-table-column label="二级分销" align="center">
          <el-table-column label="伙伴名称" align="center" prop="distributorsLevelTwoName"/>
          <el-table-column label="手机号" align="center" prop="distributorsLevelTwoPhone"/>
          <el-table-column label="分销金额/元" align="center" prop="secondaryDistributionAmount"/>
        </el-table-column>


<!--        <el-table-column label="推广门店分销" align="center">-->
<!--          <el-table-column label="门店名称" align="center" prop="storePromotionName"/>-->
<!--          <el-table-column label="分销金额/元" align="center" prop="storePromotionAmount"/>-->
<!--        </el-table-column>-->


<!--        <el-table-column label="核销门店" align="center">-->
<!--          <el-table-column label="门店名称" align="center" prop="writeOffName"/>-->
<!--          <el-table-column label="核销收入/元" align="center" prop="writeOffIncome"/>-->
<!--        </el-table-column>-->

      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listMkOrder, exportMkOrder,statistics } from '@/api/marketing/mkOrder'

export default {
  name: 'MkOrder',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 全名营销订单表格数据
      mkOrderList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        tradingHours: null,
        purchaserPhone: null,
        purchaserName: null,
      },
      orderTotal: 0,
      fristCommission: 0,
      secCommission: 0,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    }
  },
  computed: {
    totalCommission() {
      return (this.fristCommission + this.secCommission).toFixed(2)
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询全名营销订单列表 */
    getList() {
      this.loading = true
      listMkOrder(this.queryParams).then((response) => {
        this.mkOrderList = response.rows
        this.total = response.total
        this.loading = false
      })
      statistics(this.queryParams).then(response => {
        this.orderTotal = response.data.orderTotal || 0;
        this.fristCommission = response.data.fristCommission || 0;
        this.secCommission = response.data.secCommission || 0;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        orderNo: null,
        tradingHours: null,
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 详情按钮操作 */
    handDetail(row) {
      this.nowOrderNo = row.orderNo
      this.$router.push({
        path: '/orderBasic/detail',
        query: { orderNo: row.orderNo }
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$modal
        .confirm('是否确认导出所有全名营销订单数据项？')
        .then(() => {
          this.exportLoading = true
          return exportMkOrder(queryParams)
        })
        .then((response) => {
          this.$download.name(response.msg)
          this.exportLoading = false
        })
        .catch(() => {})
    },
  },
}
</script>
